package com.mzj.saas.mservice.property.repository;

import com.mzj.saas.mservice.property.entity.MatchUserHouse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.Date;
import java.util.List;

public interface MatchUserHouseRepository extends PagingAndSortingRepository<MatchUserHouse,Long>, JpaSpecificationExecutor<MatchUserHouse>, JpaRepository<MatchUserHouse, Long> {
    @Modifying
    @Query(value = " DELETE FROM m_match_user_house WHERE house_id = ?1 ",nativeQuery = true)
    public int deleteByHouseId(String houseId);

    List<MatchUserHouse> findByHouseId(String houseId);

    @Modifying
    @Query(value = "UPDATE m_match_user_house SET match_user_stock_id = NULL WHERE house_id = ?1",nativeQuery = true)
    Integer updateMatchUserId(String houseId);

    @Modifying
    @Query(value = "UPDATE m_match_user_house SET end_date = ?1 WHERE house_id = ?2",nativeQuery = true)
    Integer updateMatchEndTimeByHouseId(Date checkOutTime, String houseId);
}
